flutty-cli-agent
Version:
Flutty CLI Agent - AI-powered development assistant with web chat interface, context memory, and full tool integration using DeepSeek API
86 lines (74 loc) • 2.08 kB
text/typescript
import { NextRequest, NextResponse } from 'next/server'
import { ChatSession } from '../../../../../src/lib/chat-session'
// Access global session store
declare global {
var chatSessions: Map<string, ChatSession> | undefined
}
const chatSessions = global.chatSessions || new Map()
export async function GET(
request: NextRequest,
{ params }: { params: { sessionId: string } }
) {
try {
const { sessionId } = params
// Get the chat session
const chatSession = chatSessions.get(sessionId)
if (!chatSession) {
return NextResponse.json(
{ success: false, error: 'Chat session not found' },
{ status: 404 }
)
}
// Get session info and context
const sessionInfo = chatSession.getSessionInfo()
const context = chatSession.getContext()
return NextResponse.json({
success: true,
sessionInfo,
messages: context?.messages || [],
messageCount: context?.messages?.length || 0
})
} catch (error: any) {
console.error('Error getting chat session:', error)
return NextResponse.json(
{
success: false,
error: error.message || 'Failed to get chat session'
},
{ status: 500 }
)
}
}
export async function DELETE(
request: NextRequest,
{ params }: { params: { sessionId: string } }
) {
try {
const { sessionId } = params
// Get the chat session
const chatSession = chatSessions.get(sessionId)
if (!chatSession) {
return NextResponse.json(
{ success: false, error: 'Chat session not found' },
{ status: 404 }
)
}
// Stop and remove the session
await chatSession.stop()
chatSessions.delete(sessionId)
return NextResponse.json({
success: true,
message: 'Chat session ended successfully',
sessionId
})
} catch (error: any) {
console.error('Error ending chat session:', error)
return NextResponse.json(
{
success: false,
error: error.message || 'Failed to end chat session'
},
{ status: 500 }
)
}
}